package com.sdau.repairmaster.UIFile;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.sdau.repairmaster.R;
import com.sdau.repairmaster.logic.tools.UserUtils;

import FunctionalModule.PasswordStrength;

public class RegisterActivity_one extends AppCompatActivity implements View.OnClickListener {

    private PasswordStrength passwordStrength;
    private EditText password;
    private  EditText re_password;
    private Button first_submit;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_one);
        initview();

//        password.setText("51264a");
//        re_password.setText("51264a");
    }
    private void initview()
    {
        first_submit=findViewById(R.id.first_submit);
        re_password=findViewById(R.id.re_first_password);
        password=findViewById(R.id.first_password);

        password.setOnClickListener(this);
        re_password.setOnClickListener(this);
        first_submit.setOnClickListener(this);


    }
    @Override
    public void onClick(View view)
    {
        switch (view.getId()){
            case R.id.first_submit:
                String pwd = password.getText().toString();
                String re_pwd = re_password.getText().toString();

                if(!pwd.equals(re_pwd))
                    Toast.makeText(RegisterActivity_one.this, "两次密码输入不一致",
                            Toast.LENGTH_SHORT).show();
                else if(!UserUtils.checkPwd(pwd))
                    Toast.makeText(RegisterActivity_one.this, "输入格式有误",
                            Toast.LENGTH_SHORT).show();
                else if(UserUtils.checkPwd(pwd)){
                    String account = getIntent().getStringExtra("account");

                    startActivity(new Intent(RegisterActivity_one.this,
                            RegisterActivity_two.class)
                                .putExtra("password",password.getText().toString())
                                .putExtra("account",account));//携带账号密码进行跳转
                    finish();//销毁页面，防止用户返回至此
                }


                /*
                if(!password.getText().toString().equals(re_password.getText().toString()))
                    Toast.makeText(RegisterActivity_one.this, "两次密码输入不一致", Toast.LENGTH_SHORT).show();
                else {
                    passwordStrength=new PasswordStrength(password.getText().toString());
                    if(passwordStrength.Score()>=60)
                    {

                        startActivity(new Intent(RegisterActivity_one.this,RegisterActivity_two.class)
                                .putExtra("password",password.getText().toString()));//携带密码进行跳转
                        finish();//销毁页面，防止用户返回至此
                    }
                    else
                    {
                        Toast.makeText(RegisterActivity_one.this, "密码过于简单，请重新设置", Toast.LENGTH_SHORT).show();
                    }

                }

                 */
                break;

        }
    }

}